﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HUBS1.HCMS.Entity;
using HUBS1.HCMS.Data;
using System.Data.SqlClient;

namespace HUBS1.HCMS.SqlClient
{
    public class sql_description
    {
        /// <summary>
        /// 一条酒店描述信息
        /// </summary>
        /// <param name="id">编号</param>
        /// <param name="types">1=酒店编号 2=property编号</param>
        /// <returns></returns>
        public h_description getitem(int id,int types)
        {
            string sqlstr = "select * from H_description where property_id="+id.ToString();
            if (types == 1)
                sqlstr = "select * from H_description where hotel_id=" + id.ToString();
            try
            {
                return new h_description(ExecSql.GetDataSet(sqlstr).Tables[0].Rows[0]);
            }
            catch { return null; }
        }

        /// <summary>
        /// 新增或修改
        /// </summary>
        /// <param name="_description"></param>
        /// <returns></returns>
        public bool insertorupdate(h_description _description)
        {
            return ExecSql.InsertOrUpdateData<h_description>(_description);
        }

        public bool modifylocal(string localtion, string transport, string Longitude, string Latitude, int pid,int desid)
        {
            string sqlstr = "update hotel set locallongitude=@locallongitude,locallatitude=@locallatitude where pid="+pid.ToString()+";";
            if (desid > 0)
                sqlstr += "update h_description set location=@location,transportation=@transportation where Property_id=" + desid.ToString();
            else
                sqlstr += "insert into h_description(property_id,location,transportation) values(@property_id,@location,@transportation)";
            SqlParameter[] pam = new SqlParameter[5];
            pam[0]=new SqlParameter("@locallongitude",Longitude);
            pam[1]=new SqlParameter("@locallatitude",Latitude);
            pam[2]=new SqlParameter("@location",localtion);
            pam[3]=new SqlParameter("@transportation",transport);
            pam[4]=new SqlParameter("@property_id",pid);
            if (ExecSql.SqlExecNoquery(sqlstr, pam) > 0)
                return true;
            else
                return false;
        }

        public bool modifyotherinfo(string pid,string hy, string cy, string bc, string kl, string aq, string rh)
        {
            SqlParameter[] pam = new SqlParameter[7];
            pam[0] = new SqlParameter("@pid", pid);
            pam[1] = new SqlParameter("@hy", hy);
            pam[2] = new SqlParameter("@cy", cy);
            pam[3] = new SqlParameter("@bc", bc);
            pam[4] = new SqlParameter("@kl", kl);
            pam[5] = new SqlParameter("@aq", aq);
            pam[6] = new SqlParameter("@rh", rh);

            if (ExecSql.SqlExecNoquery("update h_description set Meetings=@hy,Dining=@cy,Transportation=@bc,Recreation=@kl where property_id=@pid", pam) > 0)
                return true;
            else
                return false;
        }


        public bool modifyfacility(int pid, string facility)
        {
            SqlParameter[] pam = new SqlParameter[2];
            pam[0]=new SqlParameter("@pid",pid);
            pam[1]=new SqlParameter("@fac",facility);
            if (ExecSql.SqlExecNoquery("update h_description set Facilities=@fac where property_id=@pid", pam) > 0)
                return true;
            else
                return false;
        }

        public bool modifyaddition(int pid, string team, string market)
        {
            SqlParameter[] pam = new SqlParameter[3];
            pam[0] = new SqlParameter("@pid", pid);
            pam[1] = new SqlParameter("@team", team);
            pam[2] = new SqlParameter("@market", market);

            if (ExecSql.SqlExecNoquery("update h_description set team=@team,market=@market where property_id=@pid", pam) > 0)
                return true;
            else
                return false;
        }

        public bool savepolicyother(int pid, string booking, string usual, string agent)
        {
            SqlParameter[] pam = new SqlParameter[4];
            pam[0] = new SqlParameter("@pid", pid);
            pam[1] = new SqlParameter("@booking", booking);
            pam[2] = new SqlParameter("@usual", usual);
            pam[3] = new SqlParameter("@agent", agent);
            if (ExecSql.SqlExecNoquery("update h_description set booking=@booking,usual=@usual,agent=@agent where property_id=@pid", pam) > 0)
                return true;
            else
                return false;
        }
    }
}
